package org.gary.base.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 类别，可以是新闻类别，产品类别，设备类别，whoCategory用于区别是谁的类别
 * @author Administrator
 *
 */
@Entity
public class Category implements lengreen.core.interfaces.Entity {
	/**
	 * 在记录日志中需要用到该方法
	 */
	@Override
	public String toString() {
		return "Category [拥有子类别数量=" + children.size() + ", createDate="
				+ createDate + ", id=" + id + ", 类别名称=" + name + ", 类别备注="
				+ notes + ", 是否可见=" + visible + ", 谁的类别=" + whoCategory
				+ ", lang=" + lang + "]";
	}

	private int id;
	private boolean visible;// 是否可见
	private String name;// 类别名称
	private String notes;// 类别备注
	/**类型归属*/
	private String whoCategory;
	private String lang;

	private Date createDate;
	private Set<Category> children = new HashSet<Category>();// 树状结构，一对多，双向
	private Category parent;// 树状，多对一，双向

	public Category() {
		setCreateDate(new Date());
		setVisible(true);
	}

	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
	public Set<Category> getChildren() {
		return children;
	}

	public void setChildren(Set<Category> children) {
		this.children = children;
	}

	@ManyToOne
	@JoinColumn(name = "parent_id")
	public Category getParent() {
		return parent;
	}

	public void setParent(Category parent) {
		this.parent = parent;
	}

	public void setWhoCategory(String whoCategory) {
		this.whoCategory = whoCategory;
	}

	public String getWhoCategory() {
		return whoCategory;
	}

	public void setLang(String lang) {
		this.lang = lang;
	}

	public String getLang() {
		return lang;
	}
}
